package com.zengjianjun.es.demo.highlevelclient.example.builder;

import com.zengjianjun.es.demo.highlevelclient.options.TimeOption;
import com.zengjianjun.es.demo.highlevelclient.param.EsQueryParam;
import com.zengjianjun.es.demo.highlevelclient.param.FieldValue;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zengjianjun
 */
@Getter
public class EsGaidQuery extends EsQueryParam {

    public static EsGaidQueryBuilder builder() {
        return new EsGaidQueryBuilder();
    }

    public EsGaidQuery(Map<String, FieldValue<?>> map, TimeOption timeOption) {
        super.putAll(map);
        super.timeOption(timeOption);
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class EsGaidQueryBuilder {

        private final Map<String, FieldValue<?>> map = new HashMap<>();

        private TimeOption timeOption;

        public EsGaidQueryBuilder source(FieldValue<String> fieldValue) {
            map.put("source", fieldValue);
            return this;
        }

        public EsGaidQueryBuilder country(FieldValue<String> fieldValue) {
            map.put("country", fieldValue);
            return this;
        }

        public EsGaidQueryBuilder event(FieldValue<String> fieldValue) {
            map.put("event", fieldValue);
            return this;
        }

        public EsGaidQueryBuilder platform(FieldValue<String> fieldValue) {
            map.put("platform", fieldValue);
            return this;
        }

        public EsGaidQueryBuilder cat(FieldValue<String> fieldValue) {
            map.put("cat", fieldValue);
            return this;
        }

        public EsGaidQueryBuilder subCat(FieldValue<String> fieldValue) {
            map.put("subCat", fieldValue);
            return this;
        }

        public EsGaidQueryBuilder includePkg(FieldValue<List<String>> fieldValue) {
            map.put("packageName", fieldValue);
            return this;
        }

        public EsGaidQueryBuilder excludePkg(FieldValue<List<String>> fieldValue) {
            map.put("packageName", fieldValue);
            return this;
        }

        public EsGaidQueryBuilder timeOption(TimeOption timeOption) {
            this.timeOption = timeOption;
            return this;
        }

        public EsGaidQuery build() {
            return new EsGaidQuery(map, timeOption);
        }
    }
}
